package Handler;

import logging.Record;
import Filter.Filter;

public abstract class Handler{
	
	protected Filter filter;
	boolean hasFilter;
	
	public Handler() {
		this.hasFilter = false;
	}
	
	/*
	 * add handler filter
	 */
	public void addFilter(Filter filter){
		if (!hasFilter){
			this.filter = filter;
			this.hasFilter = true;
		}
	}

	/*
	 * if has filter return true, else false
	 */
	public boolean hasFilter(){
		return this.hasFilter;
	}
	
	/*
	 * return the current filter
	 */
	public Filter getFilter(){
		return this.filter;
	}
	
	/*
	 * set the current filter
	 */
	public void setFilter(Filter filter){
			this.filter = filter;
			this.hasFilter = true;
	}
	
	/*
	 * return true if a record would be logged, else return false.
	 */
	public boolean messageCanWrite(Record record){
		if (this.hasFilter())
			return filter.apply(record);
		return true;
	}
	
	public abstract void write(Record record);
	
	public abstract String getName();
	
	
}
